home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_dented.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  1.3 KB  |  48 lines

  1. /*
  2.  * dented.sl -- displacement shader for dents
  3.  *
  4.  * DESCRIPTION:
  5.  *   Makes a surface appear worn and dented.
  6.  * 
  7.  * PARAMETERS:
  8.  *   Km            the amplitude of the dents
  9.  *   power           controls the fractal dimension of the dents (1 looks
  10.  *                         like previously crumpled paper or cloth, 3 looks
  11.  *                         like worn metal).
  12.  *   frequency      the frequency of the dents
  13.  *
  14.  *
  15.  * AUTHOR: written by Larry Gritz, based on the "dented" shader in
  16.  *         RenderMan Companion, but with more control parameters.
  17.  *
  18.  * HISTORY:
  19.  *      Dec 1992 -- written by lg for "Timbre Trees Examples" (jingle)
  20.  *
  21.  * last modified  12 Jan 1994 by Larry Gritz
  22.  *
  23.  * The RenderMan (R) Interface Procedures and RIB Protocol are:
  24.  *     Copyright 1988, 1989, Pixar.  All rights reserved.
  25.  * RenderMan (R) is a registered trademark of Pixar.
  26.  */
  27.  
  28.  
  29.  
  30. displacement k3d_dented( float Km = 1; float power = 3; float frequency = 1; float maxoctaves = 6; )
  31. {
  32.     float size;
  33.     float magnitude = 0;
  34.     float i;
  35.     point PP;
  36.  
  37.     PP = transform ("shader", P);
  38.     size = frequency;
  39.     for(i = 0;  i < maxoctaves;  i += 1)
  40.         {
  41.             magnitude += abs(0.5 - noise(PP*size)) / size;
  42.             size *= 2;
  43.         }
  44.     P = P - (Km * pow(magnitude, power)) * normalize(N);
  45.     N = calculatenormal(P);
  46. }
  47.  
  48.